// author：无妻徒刑

//请求截图
//每次使用该函数都会弹出截图权限请求，建议选择“总是允许”。
if (!requestScreenCapture()) {
  toast(msg);
  console.log(msg)
  exit();
};

const formatting = data => JSON.parse(JSON.stringify(data));

let frequency = 0; // 执行次数

const init = () => {
  //截图
  const img = captureScreen(); sleep(10);
  // 识别中文
  const result = gmlkit.ocr(img, "zh"); sleep(10)
  img.recycle(); //释放内存
  const res = formatting(result.children).find((obj) => obj.text === "挑战");
  if (res === undefined) {
    click(1500, 1500); sleep(10);
  } else {
    click(res.bounds.left, res.bounds.bottom);
    frequency++;
    console.log(`执行次数: ${frequency}`);
  }
}

setInterval(init, 5000)